﻿namespace Gamelight.Graphics
{
	public struct Color
	{
		private byte red;
		private byte green;
		private byte blue;
		private byte alpha;

		public Color(byte red, byte green, byte blue)
		{
			this.red = red;
			this.green = green;
			this.blue = blue;
			this.alpha = 255;
		}

		public Color(byte red, byte green, byte blue, byte alpha)
		{
			this.red = red;
			this.green = green;
			this.blue = blue;
			this.alpha = alpha;
		}

		internal Color(int colorValue)
		{
			this.red = (byte)((colorValue >> 16) & 255);
			this.green = (byte)((colorValue >> 8) & 255);
			this.blue = (byte)(colorValue & 255);
			this.alpha = (byte)((colorValue >> 24) & 255);
		}

		public byte Red { get { return red; } }
		public byte Green { get { return green; } }
		public byte Blue { get { return blue; } }
		public byte Alpha { get { return alpha; } }

		public int IntValue { get { return (this.Alpha << 24) + (this.Red << 16) + (this.Green << 8) + this.Blue; } }

		public bool Matches(Color otherColor)
		{
			if (this.alpha == 0)
			{
				return otherColor.alpha == 0;
			}

			return
				otherColor.red == this.red &&
				otherColor.green == this.green &&
				otherColor.blue == this.blue &&
				otherColor.alpha == this.alpha;
		}
	}

	public static class Colors
	{
		public static Color Black { get { return new Color(0, 0, 0); } }
		public static Color Blue { get { return new Color(0, 0, 255); } }
		public static Color Brown { get { return new Color(128, 80, 30); } }
		public static Color DarkBlue { get { return new Color(0, 0, 128); } }
		public static Color DarkGray { get { return new Color(64, 64, 64); } }
		public static Color Gray { get { return new Color(128, 128, 128); } }
		public static Color Green { get { return new Color(0, 128, 40); } }
		public static Color LightBlue { get { return new Color(128, 192, 255); } }
		public static Color LightGray { get { return new Color(192, 192, 192); } }
		public static Color Magenta { get { return new Color(255, 0, 255); } }
		public static Color Maroon { get { return new Color(128, 0, 0); } }
		public static Color Olive { get { return new Color(0, 128, 0); } }
		public static Color Orange { get { return new Color(255, 128, 0); } }
		public static Color Pink { get { return new Color(255, 128, 192); } }
		public static Color Purple { get { return new Color(128, 0, 128); } }
		public static Color Red { get { return new Color(255, 0, 0); } }
		public static Color Transparent { get { return new Color(0, 0, 0, 0); } }
		public static Color White { get { return new Color(255, 255, 255); } }
		public static Color Yellow { get { return new Color(255, 255, 0); } }
	}
}
